home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Network Support Library
/
RoseWare - Network Support Library.iso
/
btrieve
/
tur5bt.arc
/
TUR5BTRV.PAS
Wrap
Pascal/Delphi Source File
|
1988-10-14
|
8KB
|
197 lines
{**************************************************************
TUR5BTRV.PAS 10/14/88
modification of TUR4BTRV.PAS to turn it into a unit,
to fix minor bugs & reformat
uploaded by David Morgenlender 75206,1070
**************************************************************}
{$B+} {Boolean complete evaluation on}
{$I+} {I/O checking on}
{ }
{ Module Name: TUR4BTRV.PAS }
{ }
{ Description: This is the Btrieve interface for Turbo Pascal (MS-DOS). }
{ This routine sets up the parameter block expected by }
{ Btrieve, and issues interrupt 7B. It should be compiled }
{ with the $V- switch so that runtime checks will not be }
{ performed on the variable parameters. }
{ }
{ Synopsis: STAT := BTRV (OP, POS.START, DATA.START, DATALEN, }
{ KBUF.START, KEY); }
{ where }
{ OP is an integer, }
{ POS is a 128 byte array, }
{ DATA is an untyped parameter for the data buffer, }
{ DATALEN is the integer length of the data buffer, }
{ KBUF is the untyped parameter for the key buffer, }
{ and KEY is an integer. }
{ }
{ Returns: Btrieve status code (see Appendix B of the Btrieve Manual). }
{ }
{ Note: The Btrieve manual states that the 2nd, 3rd, and 5th }
{ parameters be declared as variant records, with an integer }
{ type as one of the variants (used only for Btrieve calls), }
{ as is shown in the example below. This is supported, but }
{ the restriction is no longer necessary. In other words, any }
{ variable can be sent in those spots as long as the variable }
{ uses the correct amount of memory so Btrieve does not }
{ overwrite other variables. }
{ }
{ var DATA = record case boolean of }
{ FALSE: ( START: integer ); }
{ TRUE: ( EMPLOYEE_ID: 0..99999; }
{ EMPLOYEE_NAME: packed array[1..50] of char; }
{ SALARY: real; }
{ DATA_OF_HIRE: DATE_TYPE ); }
{ end; }
{ }
{ There should NEVER be any string variables declared in the }
{ data or key records, because strings store an extra byte for }
{ the length, which affects the total size of the record. }
{ }
{ }
UNIT Tur4Btrv;
INTERFACE
USES
Dos;
FUNCTION BTRV(OP : Integer;
VAR POS, DATA;
VAR DATALEN : Integer;
VAR KBUF;
KEY : Integer)
: Integer;
{.pa}
{**************************************************************
**************************************************************}
IMPLEMENTATION
FUNCTION BTRV(OP : Integer;
VAR POS, DATA;
VAR DATALEN : Integer;
VAR KBUF;
KEY : Integer)
: Integer;
CONST
VAR_ID = $6176; {id for variable length records - 'va'}
BTR_INT = $7B;
BTR2_INT = $2F;
BTR_OFFSET = $0033;
MULTI_FUNCTION = $AB;
{ ProcId is used for communicating with the Multi Tasking Version of }
{ Btrieve. It contains the process id returned from BMulti and should }
{ not be changed once it has been set. }
{ }
ProcId : Integer = 0; { initialize to no process id }
MULTI : Boolean = False; { set to true if BMulti is loaded }
VSet : Boolean = False; { set to true if we have checked for BMulti }
TYPE
ADDR32 = RECORD {32 bit address}
OFFSET : Word;
SEGMENT : Word;
END;
BTR_PARMS = RECORD
USER_BUF_ADDR : ADDR32; {data buffer address}
USER_BUF_LEN : Integer; {data buffer length}
USER_CUR_ADDR : ADDR32; {currency block address}
USER_FCB_ADDR : ADDR32; {file control block address}
USER_FUNCTION : Integer; {Btrieve operation}
USER_KEY_ADDR : ADDR32; {key buffer address}
USER_KEY_LENGTH : Byte; {key buffer length}
USER_KEY_NUMBER : Byte; {key number}
USER_STAT_ADDR : ADDR32; {return status address}
XFACE_ID : Integer; {language interface id}
END;
VAR
STAT : Integer; {Btrieve status code}
XDATA : BTR_PARMS; {Btrieve parameter block}
REGS : Dos.Registers; {register structure used on interrrupt call}
DONE : Boolean;
BEGIN
REGS.AX := $3500 + BTR_INT;
INTR($21, REGS);
IF (REGS.BX <> BTR_OFFSET) THEN {make sure Btrieve is installed}
STAT := 20
ELSE
BEGIN
IF (NOT VSet) THEN {if we haven't checked for Multi-User version}
BEGIN
REGS.AX := $3000;
INTR($21, REGS);
IF ((REGS.AX AND $00FF) >= 3) THEN
BEGIN
VSet := True;
REGS.AX := MULTI_FUNCTION * 256;
INTR(BTR2_INT, REGS);
MULTI := ((REGS.AX AND $00FF) = $004D);
END
ELSE
MULTI := False;
END;
{make normal btrieve call}
WITH XDATA DO
BEGIN
USER_BUF_ADDR.SEGMENT := Seg(DATA);
USER_BUF_ADDR.OFFSET := Ofs(DATA); {set data buffer address}
USER_BUF_LEN := DATALEN;
USER_FCB_ADDR.SEGMENT := Seg(POS);
USER_FCB_ADDR.OFFSET := Ofs(POS); {set FCB address}
USER_CUR_ADDR.SEGMENT := USER_FCB_ADDR.SEGMENT; {set cur seg}
USER_CUR_ADDR.OFFSET := USER_FCB_ADDR.OFFSET + 38; {set cur ofs}
USER_FUNCTION := OP; {set Btrieve operation code}
USER_KEY_ADDR.SEGMENT := Seg(KBUF);
USER_KEY_ADDR.OFFSET := Ofs(KBUF); {set key buffer address}
USER_KEY_LENGTH := 255; {assume its large enough}
USER_KEY_NUMBER := KEY; {set key number}
USER_STAT_ADDR.SEGMENT := Seg(STAT);
USER_STAT_ADDR.OFFSET := Ofs(STAT); {set status address}
XFACE_ID := VAR_ID; {set lamguage id}
END;
REGS.DX := Ofs(XDATA);
REGS.DS := Seg(XDATA);
IF (NOT MULTI) THEN {MultiUser version not installed}
INTR(BTR_INT, REGS)
ELSE
BEGIN
DONE := False;
REPEAT
REGS.BX := ProcId;
REGS.AX := 1;
IF (REGS.BX <> 0) THEN
REGS.AX := 2;
REGS.AX := REGS.AX + (MULTI_FUNCTION * 256);
INTR(BTR2_INT, REGS);
IF ((REGS.AX AND $00FF) = 0) THEN
DONE := True
ELSE BEGIN
REGS.AX := $0200;
INTR($7F, REGS);
DONE := False;
END;
UNTIL (DONE);
IF (ProcId = 0) THEN
ProcId := REGS.BX;
END;
DATALEN := XDATA.USER_BUF_LEN;
END;
BTRV := STAT;
END;
END.